﻿'Description:设备维护类
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:zhunan
'create Date:2022.5.7
Imports DatabaseAccess.DBUtility
Imports BusinessRule.DTO
Imports System.Text
Imports External.APICalling
Imports System.Linq
Imports System.Data.OracleClient

Public Class ResourceMaintBusiness

#Region "设备维护"

    ''' <summary>
    ''' 设备维护（增加、更新、删除） add zhunan 2022.5.7
    ''' </summary>
    ''' <param name="strOperType">执行的操作：create、update、delete</param>
    ''' <param name="para">设备属性信息</param>
    ''' <param name="strMessage">返回消息</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ResourceMaint(ByVal strOperType As String, ByVal para As Dictionary(Of String, String), ByRef strMessage As String) As Boolean
        ResourceMaint = False
        If strOperType = "create" Or strOperType = "update" Or strOperType = "delete" Then
        Else
            ResourceMaint = False
            strMessage = "操作类型必须是create、update、delete中的一种"
            Exit Function
        End If

        If Not para.ContainsKey("resourcename") Then
            ResourceMaint = False
            strMessage = "设备编号不能为空！"
            Exit Function
        End If

        Dim dataEntityList As New List(Of ClientAPIEntity)
        Dim dataEntity As New ClientAPIEntity
        '设备编码
        dataEntity = New ClientAPIEntity
        dataEntity.ClientDataName = "Name"
        dataEntity.ClientDataValue = para("resourcename")
        dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
        dataEntityList.Add(dataEntity)

        '设备名称
        If para.ContainsKey("description") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "Description"
            dataEntity.ClientDataValue = para("description")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If

        '备注
        If para.ContainsKey("notes") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "Notes"
            dataEntity.ClientDataValue = para("notes")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If

        '设备类型
        'If para.ContainsKey("resourcetype") Then
        '    dataEntity = New ClientAPIEntity
        '    dataEntity.ClientDataName = "ResourceType"
        '    dataEntity.ClientDataValue = para("resourcetype")
        '    dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
        '    dataEntityList.Add(dataEntity)
        'End If

        '设备型号
        If para.ContainsKey("resourcefamily") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "ResourceFamily"
            dataEntity.ClientDataValue = para("resourcefamily")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
            dataEntityList.Add(dataEntity)
        End If

        '分厂
        If para.ContainsKey("factoryname") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "Factory"
            dataEntity.ClientDataValue = para("factoryname")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
            dataEntityList.Add(dataEntity)
        End If

        '工区
        If para.ContainsKey("workcentername") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "WorkCenter"
            dataEntity.ClientDataValue = para("workcentername")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
            dataEntityList.Add(dataEntity)
        End If

        '班组
        If para.ContainsKey("teamname") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "Team"
            dataEntity.ClientDataValue = para("teamname")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
            dataEntityList.Add(dataEntity)
        End If

        '是否启用
        If para.ContainsKey("isuse") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "Isuse"
            dataEntity.ClientDataValue = para("isuse")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If

        '班次
        If para.ContainsKey("workshiftid") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "WorkShiftID"
            dataEntity.ClientDataValue = para("workshiftid")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If

        '日历
        If para.ContainsKey("makecalendar") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "MakeCalendarID"
            dataEntity.ClientDataValue = para("makecalendar")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If
        '下年日历 add by longb 2023-03-28
        If para.ContainsKey("nextmakecalendar") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "NextMakeCalendarID"
            dataEntity.ClientDataValue = para("nextmakecalendar")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If

        '优先级
        If para.ContainsKey("prioritynum") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "PriorityNum"
            dataEntity.ClientDataValue = para("prioritynum")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If

        '瓶颈设备
        If para.ContainsKey("isbottleneck") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "IsBottLeneck"
            dataEntity.ClientDataValue = para("isbottleneck")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If
        '是否无限能力设备 add by longb 2023-08-23
        If para.ContainsKey("isinfinite") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "IsinFinite"
            dataEntity.ClientDataValue = para("isinfinite")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If
        '设备关联产线属性 add by longb 2024-04-01
        If para.ContainsKey("productline") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "ProductLine"
            dataEntity.ClientDataValue = para("productline")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If

        '是否虚拟设备 add by zhangrj 20250711
        If para.ContainsKey("isVirtual") Then
            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataName = "isVirtual"
            dataEntity.ClientDataValue = para("isVirtual")
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntityList.Add(dataEntity)
        End If

        Dim api As New CamstarClientAPI(para("userName"), para("passWord"))

        If strOperType = "create" Then
            ResourceMaint = api.CreateModelByStandard("resourceMaintDoc", "resourceMaint", "New", dataEntityList, strMessage)
        ElseIf strOperType = "update" Then
            ResourceMaint = api.UpdateModelByStandard("resourceMaintDoc", "resourceMaint", para("resourcename"), "", dataEntityList, strMessage)
        Else
            ResourceMaint = api.DeleteModel("resourceMaintDoc", "resourceMaint", para("resourcename"), "", "NDO", strMessage)
        End If
    End Function

    ''' <summary>
    ''' 查询设备信息 add zhunan 2022.5.7
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetResourceInfo(ByVal para As Dictionary(Of String, String)) As uMESProcessResult
        Dim strSql As String = <string>
SELECT rd.resourceid,rd.resourcename,rd.description,rd.notes,f.factoryname,w.workcentername,t.teamname,wks.workshiftname,nvl(rd.isvirtual,'0') isvirtual,
       rd.factoryid,rd.workcenterid,rd.teamid,rd.workshiftid,DECODE(rd.isuse,NULL,'是',0,'是',1,'否') isuse,mk.makecalendarname,DECODE(rd.isinfinite,1,'是',0,'否','') isinfinite,rd.combinerule, DECODE(rd.iscombinebatch,1,'是',0,'否','') iscombinebatch, rd.upperlimit,
       rt.resourcetypeid,rt.resourcetypename,rf.resourcefamilyid,rf.resourcefamilyname,rd.makecalendarid,rd.prioritynum,rd.isbottleneck,item.customobjectid productlineid,item.customobjectname productlinename
FROM resourcedef rd
LEFT JOIN Resourcetype rt ON rt.resourcetypeid = rd.resourcetypeid
LEFT JOIN factory f ON f.factoryid = rd.factoryid
LEFT JOIN Workcenter w ON w.workcenterid = rd.workcenterid
LEFT JOIN team t ON t.teamid = rd.teamid
LEFT JOIN workshift wks ON wks.workshiftid = rd.workshiftid
LEFT JOIN MAKECALENDAR mk ON mk.makecalendarid = rd.makecalendarid
LEFT JOIN Resourcefamily rf ON rf.resourcefamilyid = rd.resourcefamilyid
left join customobject item on item.customobjectid =rd.productline ---add by longb 2024-04-01 产线属性
WHERE 1=1 
</string>.Value

        '设备编码
        If para.ContainsKey("resourcename") Then
            If Not String.IsNullOrWhiteSpace(para("resourcename")) Then
                strSql += String.Format(" AND rd.resourcename LIKE '%{0}%'", para("resourcename"))
            End If
        End If

        '设备名称
        If para.ContainsKey("description") Then
            If Not String.IsNullOrWhiteSpace(para("description")) Then
                strSql += String.Format(" AND rd.description LIKE '%{0}%'", para("description"))
            End If
        End If

        '设备类型
        If para.ContainsKey("resourcetypename") Then
            If Not String.IsNullOrWhiteSpace(para("resourcetypename")) Then
                strSql += String.Format(" AND rt.resourcetypename = '{0}'", para("resourcetypename"))
            End If
        End If

        '设备型号 add zhunan 2022.6.20
        If para.ContainsKey("resourcefamilyname") Then
            If Not String.IsNullOrWhiteSpace(para("resourcefamilyname")) Then
                strSql += String.Format(" AND rf.resourcefamilyname = '{0}'", para("resourcefamilyname"))
            End If
        End If

        '启用状态
        If para.ContainsKey("isuse") Then
            If para("isuse") = "是" Then
                strSql += " AND NVL(rd.isuse,'0') = '0' "
            Else
                strSql += " AND NVL(rd.isuse,'0') = '1' "
            End If
        End If

        '分厂id
        If para.ContainsKey("factoryid") Then
            If Not String.IsNullOrWhiteSpace(para("factoryid")) Then
                If para("isNotFactory") = "1" Then '查询无分厂设备
                    strSql += String.Format(" AND (f.factoryid = '{0}' OR f.factoryid IS NULL)", para("factoryid"))
                Else
                    strSql += String.Format(" AND f.factoryid = '{0}'", para("factoryid"))
                End If
            End If
        End If

        '工区
        If para.ContainsKey("workcentername") Then
            If Not String.IsNullOrWhiteSpace(para("workcentername")) And Not para("workcentername").Equals("未维护") Then
                strSql += String.Format(" AND w.workcentername = '{0}'", para("workcentername"))
            ElseIf para("workcentername").Equals("未维护") Then
                strSql += " AND w.workcentername is null "
            End If
        End If

        '班组
        If para.ContainsKey("teamname") Then
            If Not String.IsNullOrWhiteSpace(para("teamname")) And Not para("teamname").Equals("未维护") Then
                strSql += String.Format(" AND t.teamname = '{0}'", para("teamname"))
            ElseIf para("teamname").Equals("未维护") Then
                strSql += " AND t.teamname is null "
            End If
        End If

        '班次
        If para.ContainsKey("workshiftname") Then
            If Not String.IsNullOrWhiteSpace(para("workshiftname")) Then
                strSql += String.Format(" AND wks.workshiftname = '{0}'", para("workshiftname"))
            End If
        End If

        '有限能力设备是否已维护
        If para.ContainsKey("isinfinite") Then
            If Not String.IsNullOrWhiteSpace(para("isinfinite")) Then
                If para("isinfinite") = "0" Then '未维护
                    strSql += String.Format(" AND rd.isinfinite is null")
                ElseIf para("isinfinite") = "1" Then '已维护
                    strSql += String.Format(" AND rd.isinfinite is not null")
                ElseIf para("isinfinite") = "2" Then '已维护（是）
                    strSql += String.Format(" AND rd.isinfinite = 1")
                ElseIf para("isinfinite") = "3" Then '已维护（否）
                    strSql += String.Format(" AND rd.isinfinite = 0")
                End If
            End If
        End If

        Dim paraPage As New uMESPagingDataDTO
        paraPage.CurrentPageIndex = Convert.ToInt32(para("PageIndex"))
        paraPage.PageSize = Convert.ToInt32(para("PageSize").ToString)
        paraPage.strSQL = strSql.ToString()
        Return DatabaseHelper.RunProcedureForPage(paraPage)
    End Function

    ''' <summary>
    ''' 增加设备保养信息 add zhunan 2022.5.7
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function InsertResourceUpKeepInfo(ByVal para As Dictionary(Of String, String)) As uMESProcessResult
        Dim result = New uMESProcessResult()
        Try
            If para.ContainsKey("resourceid") And para("resourceid") <> "" Then
            Else
                result.Result = False
                result.Message = "设备不存在或为空"
                Return result
                Exit Function
            End If

            If para.ContainsKey("upkeepstartdate") And para("upkeepstartdate") <> "" Then
            Else
                result.Result = False
                result.Message = "保养开始时间不存在或为空"
                Return result
                Exit Function
            End If

            If para.ContainsKey("upkeependdate") And para("upkeependdate") <> "" Then
            Else
                result.Result = False
                result.Message = "保养结束时间不存在或为空"
                Return result
                Exit Function
            End If

            Dim strsql As New StringBuilder
            strsql.AppendLine("INSERT INTO resourceupkeepinfo(resourceupkeepinfoid,resourceid,upkeepstartdate,upkeependdate) VALUES(")
            strsql.AppendFormat("'{0}',", Guid.NewGuid.ToString()) '唯一id
            strsql.AppendFormat("'{0}',", para("resourceid")) '设备id
            strsql.AppendFormat("to_date('{0}','yyyy/mm/dd hh24:mi:ss'),", para("upkeepstartdate")) '保养开始时间
            strsql.AppendFormat("to_date('{0}','yyyy/mm/dd hh24:mi:ss'))", para("upkeependdate")) '保养结束时间
            Dim rowCount As Integer = DatabaseHelper.ExecuteSql(strsql.ToString())
            If rowCount > 0 Then
                result.Result = True
                result.Message = "添加成功"
            Else
                result.Result = False
                result.Message = "添加失败"
            End If
        Catch ex As Exception
            result.Message = ex.Message
            result.Result = False
        End Try
        Return result
    End Function

    ''' <summary>
    ''' 批量删除设备保养信息 add zhunan 2022.5.7
    ''' </summary>
    ''' <param name="data"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteResourceUpKeepInfoBatch(ByVal data As DataTable) As uMESProcessResult
        Dim result = New uMESProcessResult()
        Try
            If Not data.Columns.Contains("resourceupkeepinfoid") Then
                result.Message = "未找到resourceupkeepinfoid列"
                result.Result = False
                Return result
                Exit Function
            End If

            If data.Rows.Count = 0 Then
                result.Message = "待删除的数据至少要有1条"
                result.Result = False
                Return result
                Exit Function
            End If

            Dim SQLlist As New Dictionary(Of String, OracleParameter())()
            Dim strSQL As String
            For Each dr As DataRow In data.Rows
                If dr("resourceupkeepinfoid").ToString() = "" Then
                    result.Message = "存在resourceupkeepinfoid为空的列"
                    result.Result = False
                    Return result
                    Exit Function
                End If
                strSQL = String.Format("DELETE resourceupkeepinfo t WHERE t.resourceupkeepinfoid = '{0}'", dr("resourceupkeepinfoid").ToString())
                SQLlist.Add(strSQL, Nothing)
            Next
            DatabaseHelper.ExecuteSqlTranByHash(SQLlist)
            result.Message = "删除成功"
            result.Result = True
        Catch ex As Exception
            result.Message = ex.Message
            result.Result = False
        End Try
        Return result
    End Function

    ''' <summary>
    ''' 获取设备保养记录信息 add zhangrj 2022-05-11
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetResourceMaintList(ByVal para As Dictionary(Of String, String)) As uMESProcessResult
        Dim strSql As String = <string>
        SELECT re.*,r.resourcename FROM resourceupkeepinfo re 
        LEFT JOIN Resourcedef r ON r.resourceid = re.resourceid
                               </string>.Value
        If para.ContainsKey("resourceid") Then
            If Not String.IsNullOrWhiteSpace(para("resourceid").ToString) Then
                strSql += String.Format(" WHERE re.resourceid = '{0}'", para("resourceid").ToString)
            End If
        End If
        Dim paraPage As New uMESPagingDataDTO
        paraPage.CurrentPageIndex = Convert.ToInt32(para("PageIndex"))
        paraPage.PageSize = Convert.ToInt32(para("PageSize").ToString)
        paraPage.strSQL = strSql.ToString()
        Return DatabaseHelper.RunProcedureForPage(paraPage)
    End Function


    ''' <summary>
    ''' 获取设备类型 add zhangrj 2022-05-10
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetResourceTypeInfo() As DataTable
        Dim strSql As String = <string>
          SELECT re.resourcetypeid,re.resourcetypename FROM resourcetype re
          </string>.Value
        Return DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
    End Function

    ''' <summary>
    ''' 获取日历 add zhangrj 2022-05-11
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetMakeCalendarInfo() As DataTable
        Dim strSql As String = <string>
          SELECT m.makecalendarid,m.makecalendarname FROM MAKECALENDAR m WHERE m.isuse ='0'
          </string>.Value
        Return DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
    End Function
    ''' <summary>
    ''' 获取设备人员信息
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetResAndEmpInfo(ByVal para As Dictionary(Of String, String)) As uMESProcessResult
        Dim strSql As String = <string>
          SELECT Distinct e.employeeid,e.fullname,e.employeename,w.workcentername,t.teamname FROM employeeresourcelist esl
          LEFT JOIN employee e ON e.employeeid = esl.employeeid
          LEFT JOIN team t ON t.teamid = e.orgteamid
          LEFT JOIN WORKCENTER w ON w.workcenterid = e.orgworkcenterid
          WHERE esl.resourcelistid = '{0}'
          </string>.Value
        Dim paraPage As New uMESPagingDataDTO
        paraPage.CurrentPageIndex = Convert.ToInt32(para("PageIndex"))
        paraPage.PageSize = Convert.ToInt32(para("PageSize").ToString)
        paraPage.strSQL = String.Format(strSql, para("ResourceID"))
        Return DatabaseHelper.RunProcedureForPage(paraPage)
    End Function

    ''' <summary>
    ''' 查询用户
    ''' </summary>
    ''' <param name="query"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetEmployee(ByVal query As String) As uMESProcessResult
        Dim result = New uMESProcessResult()
        Dim strSql As String = <string>
SELECT e.employeeid id,e.employeename,e.fullname,e.employeename || '(' || e.fullname || ')' name
FROM employee e 
WHERE UPPER(e.employeename) LIKE '%{0}%' OR UPPER(e.fullname) LIKE '%{0}%'
          </string>.Value
        strSql = String.Format(strSql, query.ToString().ToUpper())
        result.DBTable = DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
        result.Message = ""
        result.Result = True
        Return result
    End Function

#End Region

#Region "设备负荷"
    ''' <summary>
    ''' 获取设备列表 add zhangrj 2022-05-25
    ''' </summary>
    ''' <param name="factoryId">分厂ID</param>
    ''' <param name="resourceName">设备编码</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetResourceInfoForLoad(ByVal factoryId As String, ByVal resourceName As String) As DataTable
        Dim strSql As String = "SELECT r.resourceid, r.resourcename,r.description FROM resourcedef r where 1 = 1"
        If Not String.IsNullOrWhiteSpace(factoryId) Then
            strSql += String.Format(" and r.factoryid='{0}'", factoryId)
        End If
        If Not String.IsNullOrWhiteSpace(resourceName) Then
            strSql += String.Format(" and r.resourcename like '%{0}%'", resourceName)
        End If
        Return DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
    End Function

    ''' <summary>
    ''' 获取设备相关表
    ''' </summary>
    ''' <param name="resourceId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetApsResourceLinkDt(ByVal resourceId As String) As DataSet
        Dim ds As New DataSet
        '查询设备班次信息
        Dim strSql As String = <string>
SELECT * FROM workshift w
LEFT JOIN resourcedef r ON r.workshiftid = w.workshiftid
WHERE r.resourceid = '{0}' and w.isuse = 0                              
                              </string>.Value
        strSql = String.Format(strSql, resourceId)
        Dim dtWorkshift As DataTable = New DataTable()
        dtWorkshift = DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
        dtWorkshift.TableName = "dtWorkshift"
        ds.Tables.Add(dtWorkshift)
        '查询设备保养记录
        strSql = <string>
SELECT * FROM ResourceUpKeepInfo rs WHERE rs.resourceid = '{0}'                          
                              </string>.Value
        strSql = String.Format(strSql, resourceId)
        Dim dtResourceUpKeep As DataTable = New DataTable()
        dtResourceUpKeep = DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
        dtResourceUpKeep.TableName = "dtResourceUpKeep"
        ds.Tables.Add(dtResourceUpKeep)
        '查询设备排产中派工最早的时间，报工最晚的时间
        strSql = <string>
SELECT min(nvl(csd.recvdate,csd.startworkdate)) AS startdate,max(csr.reportdate) AS enddate FROM apsplandetail apd 
LEFT JOIN ContainerStepDispatch csd ON csd.workflowstepid = apd.workflowstepid AND csd.containerid = apd.containerid
LEFT JOIN containersteprecord csr ON csr.workflowstepid = apd.workflowstepid AND csr.containerid = apd.containerid
WHERE apd.resourceid = '{0}'                      
                              </string>.Value
        strSql = String.Format(strSql, resourceId)
        Dim dtReportDispatchDate As DataTable = New DataTable()
        dtReportDispatchDate = DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
        dtReportDispatchDate.TableName = "dtReportDispatchDate"
        ds.Tables.Add(dtReportDispatchDate)
        Return ds
    End Function
    ''' <summary>
    ''' 判断工厂/设备的某天是否节假日 add zhangrj 2022-05-26
    ''' </summary>
    ''' <param name="param"></param>
    ''' <param name="d"></param>
    ''' <param name="type">0工厂，1设备</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function IsHolidayDate(ByVal param As String, ByVal d As Date, ByVal type As Integer) As Boolean
        Dim strSql As String = ""
        If type = 0 Then '工厂
            strSql = <string>
SELECT m.holidaydate FROM Factory f
LEFT JOIN MAKECALENDARDETAIL m ON m.makecalendarid = f.makecalendarid 
WHERE f.factoryid = '{0}' AND m.holidaydate IS NOT NULL
                     </string>.Value
        ElseIf type = 1 Then '设备
            strSql = <string>
SELECT m.holidaydate FROM resourcedef r
LEFT JOIN MAKECALENDARDETAIL m ON m.makecalendarid = r.makecalendarid 
WHERE r.resourceid = '{0}' AND m.holidaydate IS NOT NULL
                     </string>.Value
        End If
        strSql = String.Format(strSql, param)
        Dim makeCalendarDt As DataTable = DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
        If makeCalendarDt.AsEnumerable().Where(Function(r) Date.Parse(r("Holidaydate").ToString()).Date = d.Date).AsDataView.Count > 0 Then
            Return True
            Exit Function
        End If
        Return False
    End Function

    ''' <summary>
    ''' 获取设备型号 add zhunan 2022.6.20
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetResourceFamily() As DataTable
        Dim strSql As String = <string>
          SELECT pf.resourcefamilyid,pf.resourcefamilyname FROM Resourcefamily pf
          </string>.Value
        Return DatabaseHelper.Query_ReturnDatTable(strSql.ToString)
    End Function
#End Region

End Class
